package tax;

public class FeeStrategy implements Comparable<FeeStrategy> {

    private int left;
    private int right;
    private double rate;
    private double fixed;

    public FeeStrategy(int left, int right, double rate, double fixed){
        this.left = left;
        this.right = right;
        this.rate = rate;
        this.fixed = fixed;
    }

    public double fee(double amount){
        if (amount < this.left){
            return 0d;
        }
        if (amount >= this.right){
            return (this.right-this.left)*this.rate + this.fixed;
        }
        return (amount - this.left)*this.rate + this.fixed;
    }

    public int getLeft() {
        return left;
    }

    public void setLeft(int left) {
        this.left = left;
    }

    public int getRight() {
        return right;
    }

    public void setRight(int right) {
        this.right = right;
    }

    public double getRate() {
        return rate;
    }

    public void setRate(double rate) {
        this.rate = rate;
    }

    public double getFixed() {
        return fixed;
    }

    public void setFixed(double fixed) {
        this.fixed = fixed;
    }

    public int compareTo(FeeStrategy o) {
        return this.right - o.getRight();
    }
}
